/*
 * GTFSRoutes.java
 * 
 * Created by demory on Jul 6, 2009, 3:17:23 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.core.transit.gtfs;

import java.io.File;
import java.util.List;
import org.fpdev.core.Scenario;
import org.fpdev.core.transit.Provider;
import org.fpdev.core.transit.Route;
import org.fpdev.core.transit.Routes;
import org.fpdev.core.transit.TransitPath;

/**
 *
 * @author demory
 */
public class GTFSRoutes extends GTFSDBTable {

  public GTFSRoutes(File file, GTFSImporter importer) {
    super("routes", file, importer);
  }

  public void initRoutes(Routes rtes, Scenario s, Provider p) {
    int idCol = columnNames_.get("route_id");
    int nameCol = columnNames_.get("route_long_name");
    List<String[]> allRows = getData();
    for(String[] row : allRows) {
      //System.out.println("adding rte "+row[idCol]);
      rtes.add(new Route(s, p, row[idCol], row[nameCol]));
    }
  }

  public TransitPath.Type getRouteType(Route rte) {
    List<String[]> results = db_.getData(name_, "route_id = \""+rte.getID()+"\"");
    if(results.size() == 0) return null;

    int type = Integer.parseInt(results.get(0)[columnNames_.get("route_type")]);
    switch(type) {
      case 0: return TransitPath.Type.LIGHTRAIL;
      case 1: return TransitPath.Type.METRO;
      case 2: return TransitPath.Type.REGIONALRAIL;
      case 3: return TransitPath.Type.BUS;
    }

    return null;
  }
}
